const api = require('../../../ws_micro_shop/utils/api.js');
const app = getApp();

let is_more = false;
Page({
  data: {
    money:0,
    unit: '',
    abnorData: {
      imgSrc: '/common/static/images/abnor-04.png',
      text: '暂无数据',
    },
    typ: '',
    date_1: '',
  },
  onLoad(options) {
    let that = this;
    let opts = options || {};
    if (opts.shop_id) {
      app.ws_micro_shop_globalData.shopid = opts.shop_id;
    }
    this.setData({
      money: opts.money,
      typ: opts.type,
    });
    app.loadCurrencyUnit().then(res => {
      that.setData({
        unit: res.unit,
      });
    });
    that.getData();
  },
  getData() {
    let that = this;
    wx.showLoading({
      title: '加载中',
      mask: true,
    });
    app.ws_micro_shoprequest({
      url: api.adminer.onpay_log,
      data: {
        date: that.data.date_1,
        type: that.data.typ,
      },
      success: function (res) {
        that.setData({
          list: res.data.list,
          setting: res.data.setting,
          date_1: res.data.date,
          date: res.data.date.replace('-', '年') + '月',
        });
        wx.hideLoading();
        is_more = false;
      },
    });
  },
  onShow() {
    app.pageOnLoad(this);
  },
  dateChange(e) {
    if (is_more) {
      return;
    }
    is_more = true;
    let date_1 = e.detail.value;
    let date = date_1.replace('-', '年') + '月';
    this.setData({
      date,
      date_1,
    });
    this.getData();
  },
  dateUp() {
    let that = this;
    if (is_more) {
      return;
    }
    is_more = true;
    let date_1 = that.data.date_1;
    let d = new Date(date_1);
    d.setMonth(d.getMonth() + 1);
    let m = d.getMonth() + 1;
    m = m.toString();
    m = m[1] ? m : '0' + m;
    that.setData({
      date: d.getFullYear() + '年' + m + '月',
      date_1: d.getFullYear() + '-' + m,
    });
    that.getData();
  },
  dateDown() {
    let that = this;
    if (is_more) {
      return;
    }
    is_more = true;
    let date_1 = that.data.date_1;
    let d = new Date(date_1);
    d.setMonth(d.getMonth() - 1);
    let m = d.getMonth() + 1;
    m = m.toString();
    m = m[1] ? m : '0' + m;
    that.setData({
      date: d.getFullYear() + '年' + m + '月',
      date_1: d.getFullYear() + '-' + m,
    });
    that.getData();
  },
  collectFormId(e) {
    app.collectFormId(e);
  },
});
